$(function(){
	$(".bookshelf-list").popoverTwo();
	//界面初始化
	initView();	
});
function initView(){
	var managerSearch ={};
	managerSearch.phName   ="";	
	managerSearch.insName  ="";
	managerSearch.status   ="";
	managerSearch.preprintedNo ="";
	managerSearch.orderId ="";
	managerSearch.policyRef ="";
	managerSearch.createDateFrom ="";
	managerSearch.createDateTo ="";
	var manager = JSON.parse(getQueryString("data"));
	if(manager){
		$('#selectForm').formEdit(manager);
		managerSearch=manager;
	}
	managerSearch.sortDir ="desc";
	managerSearch.updateDateFrom ="";
	managerSearch.updateDateTo ="";
	managerSearch.sortField ="";
	padMarketing.ajaxNormal(
			"/pad_marketing/ordermanager/search.action",
			managerSearch,
			function (data){
				handleData(data);	
			},
			function(data){},
			true,
			true,
			"系统正在查询您名下订单，请耐心等待"
	);
}
function search(){	
	var start =$("input[name='createDateFrom']").val();
	var end =$("input[name='createDateTo']").val();
	if(new Date(end).getTime()-new Date(start).getTime() <0){
		alertMsg("起始日期不能大于结束日期");
		return;
	}
	closeDiv('open1');
	$("#orderManagerList").html("");
	var managerSearch =$("#selectForm").serializeObject();
	padMarketing.ajaxNormal(
			"/pad_marketing/ordermanager/search.action",
			managerSearch,
			function (data){
				handleData(data);	
			},
			function(data){},
			true,
			true,
			"系统正在查询您名下订单，请耐心等待"
	);
}
function handleData(json){
	var html="";
	html+=' <div class="blank-5"></div>';
	for(var i in json)
	{
		var app = json[i];
		html+='<dl class="bookshelf-list span2">';
	    html+='<dt orderId ="'+app.orderId+'" status ="'+app.status+'">';  
	    html+='<div class="img-box">';  
	    
	    html+=   "<img src=\'/portal/resources/images/product/SJ_"+ app.productId +".jpg\'>";
	    if(app.status=="F"){
       	 html+=   "<label class='sort sort-success'><i>已支付</i></label>";
        }else if(app.status=="P"){
       	 html+=   "<label class='sort sort-danger'><i>待支付</i></label>";
        }else if(app.status=="O"){		        	
       	 html+=   "<label class='sort sort-warning'><i>人工核保</i></label>";
        }else if(app.status=="C"){
       	 html+=   "<label class='sort sort-gray'><i>已撤单</i></label>";
        }else if(app.status=="I"){
       	 html+=   "<label class='sort sort-purple'><i>录入中</i></label>";
        }else if(app.status=="U"){
       	 html+=   "<label class='sort sort-info'><i>待拍照</i></label>";
        }else if(app.status=="S"){
       	 html+=   "<label class='sort sort-primary'><i>待签名</i></label>";
        }
	    
	    html+='</div>';  
	    html+=   '<div class="show">'; 
	    html+=    '<div class="popover-panel hide">';  
	    html+=     '<i class="popover-sort"></i>';  
	    
	    if(app.status!="I"){
       	 	html+=   "<a  onclick='lookManager(this,3)' class='text-center'>";
            html+=   " <p class='icon icon-circle-view'></p>";
            html+=   "  <p class='purple font-14'>只读</p>";
            html+=   "</a>";
        }	
        if(app.status=="S"){
       	 	 html+=   "<a  onclick='writeName(this,3)' class='text-center'>";
	         html+=   " <p class='icon icon-sign'></p>";
	         html+=   " <p class='blue-d font-14'>签名</p>";
	         html+=   "</a>";
        } 
        if(app.status=="U"){
       	 	 html+=   "<a  onclick='takePhotoM(this,3)' class='text-center'>";
	         html+=   " <p class='icon icon-photo'></p>";
	         html+=   " <p class='yellow font-14'>拍照</p>";
	         html+=   "</a>";
        } 
        if(app.allowPayment=="Y"&&app.salesTool=="APP"){
       	 	 html+=   "<a   onclick='payMoney(this,3)' class='text-center'>";
	         html+=   " <p class='icon icon-circle-pay'></p>";
	         html+=   " <p class='green font-14'>支付</p>";
	         html+=   "</a>";
        }
        if(app.allowContinue=="Y"&&app.salesTool=="APP"){
       	 	 html+=   "<a  onclick='changeManager(this,3)' class='text-center'>";
	         html+=   " <p class='icon icon-jxtb'></p>";
	         html+=   " <p class='blue-l font-14'>继续投保</p>";
	         html+=   "</a>";
        } 
        if(app.allowDel=="Y"&&app.salesTool=="APP"){
       	 	 html+=   "<a  onclick='deleteManager(this,3)' class='text-center'>";
	         html+=   " <p class='icon icon-remove-sm'></p>";
	         html+=   " <p class='red font-14'>删除</p>";
	         html+=   "</a>";
        }
       if(app.allowCbi=="Y"&&app.salesTool=="APP"){
    	    html+=   "<a  class='text-center'>";
	        html+=   " <p class='icon icon-circle-edit sm'></p>";
	        html+=   " <p class='blue font-14'>撤单</p>";
	        html+=   "</a>";
       }	
        html+=   "<a  onclick='copyManager(this,3)' class='text-center'>";
        html+=   "  <p class='icon icon-circle-copy'></p>";
        html+=   "  <p class='orange font-14'>复制</p>";
        html+=   "</a>";
        
	    html+=      '</div>';
	    html+=    '</div>';
	    html+=    '<div class="check-list hide">';
	    html+=     '<input type="checkbox">'; 
	    html+=      '<label for="">&nbsp;</label>';
	    html+=    '</div>';
	    html+=  '</dt>';
	    html+=  '<dd>';
	    html+=   '<h4 class="blue b font-16 lh-30">'+HtmlEncode(app.productName)+'</h4>'; 
	    html+=    '<p class="lh-30 gray font-14">投保人：'+HtmlEncode(app.phName)+'</p>';
	    html+=    '<p class="lh-30 gray font-14">订单号：'+app.orderId+'</p>';
	    html+=    "<p class='lh-30 gray font-14'>保单号："+$.trim(app.policyRef)+"</p>";
	    html+=    '<p class="lh-30 gray font-14">更新时间：'+HtmlEncode(app.updateDate)+'</p>';
	    html+=  '</dd>';
	    html+= '</dl>';
	}
	$("#orderManagerList").html(html);
	$("dt").each(function(index,me){
		var orderId = $(me).attr("orderId");
		for(var k in json){
			var app = json[k];
			if(orderId==app.orderId){
				$(me).data("data",app);
			}
		}
		
	});
	$(".bookshelf-list").popoverTwo();
	if(myScroll)
		myScroll.refresh();
	}
//书架操作按钮弹出框
$.fn.popoverTwo=function(){
	var popoverClick=$(this).find("dt");
	$(popoverClick).click(function(e){
		var showDocument=$(this).find(".popover-panel");
       	$(showDocument).show();
        e.stopPropagation();
        $(this).siblings().find(".popover-panel").hide();
    });
    $(".popover-panel").click(function(e){
	    e.stopPropagation();
	});
	$(document.body).click(function(){
     	$(".popover-panel").hide();
   	});
}
function switchHtml(type){
	var managerSearch =$("#selectForm").serializeObject();
	location.href="/pad_marketing/ordermanager/"+type+".action?data="+encodeURIComponent(JSON.stringify(managerSearch));
}
function changePayMoney(me,index){
	window.location.href="/pad_marketing/main/editPay.action?url=ordermanager/"+orderManager(index)+".action";
}
function payMoneyHref(me,index){
	window.location.href="/pad_marketing/main/pay.action?url=ordermanager/"+orderManager(index)+".action";
}